package kk.yiyi.myapplication;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class SelectDataService {
    public void selectData(String pid, final SelectListener selectListener)
    {
        OkHttpClient okHttpClient = new OkHttpClient();
        RequestBody requestBody = new FormBody.Builder().add("pid",pid)
                .build();
        Request request = new Request.Builder()
                .url("https://alias.api.shengnuoxun.com/normal/getRegion")
                .post(requestBody)
                .build();

        okHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                selectListener.fail(e.toString());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //解析php返回的json数据
                selectListener.success(response.body().string());
            }
        });
    }
}
